#include"ProcessServer.h"
#include<string.h>
ProcessServer::ProcessServer(int fd, EpollReactor *reactor)
{
    m_reactor=reactor;
    //添加任务
    parser=new ParseRequest();
    FdInfo info(fd,1,ProcessRead,ProcessWrite,ProcessDestroy,(void*)this);
    m_info=info;
    m_reactor->SelectTask(info,EventType::ADD);
}

ProcessServer::~ProcessServer()
{
    delete parser;
}

int ProcessServer::ProcessWrite(void*server)
{
    ProcessServer*p=(ProcessServer*)server;
    p->parser->PerformActions();
    delete p;
    return 0;
}

int ProcessServer::ProcessRead(void*server)
{
    ProcessServer*p=(ProcessServer*)server;
    int ret=p->parser->Processingrequest(p->m_info.getsocket());  //解析请求数据
    if(ret==0)
    {
        return ret;
    }
    p->m_info.changeEvent(Event::WRITEEVENT);
    p->m_reactor->SelectTask(p->m_info,EventType::MODIF);
    return 1;
}

int ProcessServer::ProcessDestroy(void*server)
{
    return 0;
}
